Conversation
auberonedu
left a comment
There was a problem hiding this comment.
Nice job! See comments below for a few things to consider. Make sure to always be running your code and checking that the output matches what's expected.
|
|
||
| public static void main(String[] args) { | ||
| // Create an empty ArrayList of Strings and assign it to a variable of type List | ||
| ArrayList<String> EmptyList = new ArrayList<>(); |
There was a problem hiding this comment.
Remember to use interface types where appropriate (List)
Also, in general we have our variables and methods in Java be in camelCase, where the first letter is lowercase. We have classes and interfaces be capitalized.
| public static void main(String[] args) { | ||
| // Create a HashMap with String keys and Integer values and | ||
| // assign it to a variable of type Map | ||
| HashMap<String, Integer> workingMap = new HashMap<>(); |
There was a problem hiding this comment.
Remember to use interface types where appropriate (Map)
| for(int i = 0; i < workingMap.size(); i++) | ||
| { | ||
| System.out.println(workingMap.keySet()); | ||
| } | ||
| // Iterate over the values of the map, printing each value | ||
|
|
||
|
|
||
| for(int i = 0; i < workingMap.size(); i++) | ||
| { | ||
| System.out.println(workingMap.values()); | ||
| } | ||
| // Iterate over the entries in the map, printing each key and value | ||
|
|
||
| for(int i = 0; i < workingMap.size(); i++) | ||
| { | ||
| System.out.println(workingMap); | ||
| } |
There was a problem hiding this comment.
These don't quite work. This goes and repeatedly prints out all of the keys, then all of the values, then the entire set. We want them one at a time. Consider using a for-each loop for these. Make sure to run your code to check whether it does what you're wanting.
| String name; | ||
| // Declare a private int instance variable for the age of the person | ||
|
|
||
| int age; |
There was a problem hiding this comment.
You need to public and private access modifiers to make these have the access specified by the comments.
| public class SetPractice { | ||
| public static void main(String[] args) { | ||
| // Create a HashSet of Strings and assign it to a variable of type Set | ||
| HashSet<String> hashSetValue = new HashSet<String>(); |
There was a problem hiding this comment.
Remember to use interface types where appropriate (Set)
| public static void main(String[] args) { | ||
| // Create a string with at least 5 characters and assign it to a variable | ||
| String letters = "Hello World"; | ||
| String AssignString = letters; |
There was a problem hiding this comment.
Ditto here and elsewhere on camelCase
| } | ||
|
|
||
| // Create an ArrayList of Strings and assign it to a variable | ||
| ArrayList<String> ValueList = new ArrayList<String>(); |
There was a problem hiding this comment.
Remember to use interface types where appropriate (List)
No description provided.